﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GUI.PhanQuyen
{
    public partial class frmXuLyNhomQuyen : Form
    {
        public delegate void AddNQ(Entities.NhomQuyen nq);
        public AddNQ ThemNQ;

        public Entities.NhomQuyen[] anq;
        public frmXuLyNhomQuyen()
        {
            InitializeComponent();
        }

        private void btnHuyBo_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmXuLyNhomQuyen_Load(object sender, EventArgs e)
        {

        }

        private void btnDongY_Click(object sender, EventArgs e)
        {
            if (txtNhomQuyen.Text.Trim() == null)
            {
                MessageBox.Show("Phải nhập tên nhóm quyền");
                return;
            }
            if (anq != null)
            {
                foreach (Entities.NhomQuyen item in anq)
                {
                    if (item.TenNhomQuyen == txtNhomQuyen.Text)
                    {
                        MessageBox.Show("Nhóm quyền đã tồn tại");
                        return;
                    }
                }
            }
            Entities.NhomQuyen nq = new Entities.NhomQuyen();
            nq.TenNhomQuyen = txtNhomQuyen.Text;
            nq.isDeleted = true;
            nq.TK = Common.StaticVariable.User;
            int i = Common.StaticVariable.InterfaceObject.InsertNhomQuyen(nq);
            if (i == 1)
            {
                ThemNQ(nq);
            }
            else
            {
                MessageBox.Show("Thêm thất bại");
            }
            this.Close();
        }

        private void txtNhomQuyen_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (8 != e.KeyChar)
            {
                if (txtNhomQuyen.Text.Length > 10 || !char.IsLetter(e.KeyChar))
                {
                    e.Handled = true;
                }
            }
        }



    }
}
